<template>
  <a-modal
    title="查看工艺路线表"
    width="80%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :md="12" :sm="24">
            <a-form-item label="编码" :labelCol="labelCol_T" :wrapperCol="wrapperCol_T" has-feedback>
              <a-input
                readOnly
                placeholder="请输入编码"
                v-decorator="['code', { rules: [{ message: '请输入编码！' }] }]"
              />
            </a-form-item>
          </a-col>
          <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
          <a-col :md="12" :sm="24">
            <a-form-item label="名称" :labelCol="labelCol_T" :wrapperCol="wrapperCol_T" has-feedback>
              <a-input
                placeholder="请输入工艺路线名称"
                v-decorator="['name', { rules: [{ required: true, message: '请输入工艺路线名称！' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <WorkRouteTable
          :oldTableData="tableData"
          :disabled="true"
          :key="value"
          :oldworkRouteData="workRouteData"
        >
        </WorkRouteTable>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea
            readOnly
            placeholder="请输入备注"
            v-decorator="['remarks', { rules: [{ message: '请输入备注！' }] }]"
          />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import WorkRouteTable from './workRouteTable.vue'
export default {
  components: { WorkRouteTable },
  data() {
    return {
      tableData: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      labelCol_T: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol_T: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      value: 0,
      workRouteData: {}
    }
  },
  methods: {
    // 初始化方法
    open(record) {
      this.value++
      this.visible = true
      this.tableData = []
      this.tableData = record.workStepRouteList
      setTimeout(() => {
        this.form.setFieldsValue({
          code: record.code,
          id: record.id,
          name: record.name,
          remarks: record.remarks
        })
      }, 100)
      this.workRouteData = {
        code: record.code,
        id: record.id,
        name: record.name,
        remarks: record.remarks
      }
    },
    handleSubmit() {
      this.form.resetFields()
      this.visible = false
      this.$emit('ok')
    },
    handleCancel() {
      this.form.resetFields()
      this.visible = false
      this.$emit('ok')
    }
  }
}
</script>
